home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / euphor14.zip / WHERE.EX < prev    next >
Text File  |  1996-05-24  |  2KB  |  79 lines

  1. -- search the PATH for a file
  2. -- usage:  where.bat filename
  3. -- (give complete file name including .exe .bat etc.)
  4.  
  5. include file.e
  6.  
  7. constant TRUE = 1
  8. constant SCREEN = 1, ERROR = 2
  9.  
  10. sequence path
  11. integer p
  12.  
  13. function next_dir()
  14. -- get the next directory name from the path sequence   
  15.     sequence dir
  16.     
  17.     if p > length(path) then
  18.     return -1
  19.     end if
  20.     dir = ""
  21.     while p <= length(path) do
  22.     if path[p] = ';' then
  23.         p = p + 1
  24.         exit
  25.     end if
  26.     dir = dir & path[p]
  27.     p = p + 1
  28.     end while
  29.     if length(dir) = 0 then
  30.     return -1
  31.     end if
  32.     return dir
  33. end function
  34.  
  35.  
  36. procedure search_path()
  37. -- main routine
  38.     sequence file, cmd, full_path
  39.     object dir_name, dir_info
  40.     
  41.     cmd = command_line()
  42.     if length(cmd) < 3 then
  43.     puts(ERROR, "usage: ex where file\n")
  44.     abort(1)
  45.     end if
  46.     
  47.     path = getenv("PATH")
  48.     if atom(path) then
  49.     puts(ERROR, "NO PATH?\n")
  50.     abort(1)
  51.     end if
  52.     path = ".;" & path -- check current directory first
  53.     
  54.     file = cmd[3]
  55.     p = 1
  56.     while TRUE do
  57.     dir_name = next_dir()
  58.     if atom(dir_name) then
  59.         exit
  60.     end if
  61.     
  62.     full_path = dir_name & '\\' & file
  63.     dir_info = dir(full_path) 
  64.     if sequence(dir_info) then
  65.         -- file or directory exists
  66.         if length(dir_info) = 1 then
  67.         -- must be a file
  68.         printf(SCREEN, "%4d-%02d-%02d %2d:%02d",
  69.               dir_info[1][D_YEAR..D_MINUTE])
  70.         printf(SCREEN, "  %d  %s\n", 
  71.            {dir_info[1][D_SIZE], dir_name & '\\' & dir_info[1][D_NAME]})
  72.         end if
  73.     end if
  74.     end while
  75. end procedure
  76.  
  77. search_path()
  78.  
  79.